import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import { registerMicroApp } from './config'

import ElementUI from 'element-ui';
//样式文件需要单独引入
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(VueRouter)
Vue.use(ElementUI);
// 获取原型对象push函数
const VueRouterPush = VueRouter.prototype.push
// 修改原型对象中的push函数
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
Vue.config.productionTip = false

const routes = [
  { path: '/foo', component: () => import("./views/fooCom.vue") },
  { path: '/bar', component: () => import("./views/barCom.vue") }
]
const router = new VueRouter({
  mode: 'history',
  routes // (缩写) 相当于 routes: routes
})

router.beforeEach((to, from, next) => {
  console.log(from);
  console.log(to);
  if (to.path == '/') {
    next({ path: '/subapp1/' })
  } else {
    next()
  }
});

new Vue({
  el: "#app",
  router,
  render: h => h(App),
  mounted() {
    registerMicroApp();
  }
})
